<!--
* @description  参数1
* @fileName  tabBarItem
* @author userName
* @date 2022-03-15 15:58:52
* @version V1.0.0
!-->
<template>
  <div id="tab-bar-item" @click="btnClick">
    <div v-if="!isActive">
      <slot name="item-icon"></slot>
    </div>
    <div v-else>
      <slot name="item-active"></slot>
    </div>
    <div :style="activeStyle">
      <slot name="item-text"></slot>
    </div>
  </div>
</template>

<script>
  export default {
    name: 'tabBarItem',
    props: { // 父辈向子辈传参
      path: String,
      activeColor: {
        type: String,
        default: 'red'

      }
    },
    data() {
      return {

      }
    },
    created() { // 实例被创建之后执行代码

    },
    computed: { // 计算属性
      isActive() {
        return this.$route.path.indexOf(this.path) !== -1
      },
      activeStyle() {
        return this.isActive ? {
          color: this.activeColor
        } : {}
      }
    },
    components: { // 组件的引用

    },
    methods: { // 方法
      btnClick() {
        this.$router.push(this.path).catch((err) => err)

      }
    },
    mounted() { // 页面进入时加载内容

    },
    watch: { // 监测变化

    }
  }

</script>
<style scope>
  #tab-bar-item {
    flex: 1;


  }

  #tab-bar-item img {
    width: 24px;
    height: 24px;
    margin-top: 1px;
    vertical-align: middle;
  }

</style>
